﻿namespace VoiceDominion
{
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Text;
    using System.Windows.Controls;

    public class TextBoxStreamWriter : TextWriter
    {
        private TextBox textBox = null;

        public TextBoxStreamWriter(TextBox output)
        {
            this.textBox = output;
        }

        public override Encoding Encoding
        {
            get { return System.Text.Encoding.UTF8; }
        }

        public override void Write(char value)
        {
            base.Write(value);
            this.textBox.Dispatcher.BeginInvoke(new Action(() =>
            {
                this.textBox.AppendText(value.ToString());
            })); // When character data is written, append it to the text box. 
        }
    }
}
